//
//  ViewController.m
//  ControlFun
//
//  Created by 小白 on 16/2/18.
//  Copyright © 2016年 小白. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIActionSheetDelegate>

@end

@implementation ViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //代码实现图片的拉伸
    UIImage *img1 = [UIImage imageNamed:@"whiteButton"];
    UIImage *img2 = [UIImage imageNamed:@"blueButton"];
    
    UIEdgeInsets insters = UIEdgeInsetsMake(0, 12, 0, 12);
    UIImage *img3 = [img1 resizableImageWithCapInsets:insters resizingMode:UIImageResizingModeStretch];
    UIImage *img4 = [img2 resizableImageWithCapInsets:insters resizingMode:UIImageResizingModeStretch];
    [self.btnall setBackgroundImage:img3 forState:UIControlStateNormal];
    [self.btnall setBackgroundImage:img4 forState:UIControlStateHighlighted];
    
    [self.view addSubview:self.btnall];
    
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)backgroundevent:(UIControl *)sender {
    //结束编辑
    [self.view endEditing:YES];
}

- (IBAction)segementchage:(UISegmentedControl *)sender {
    //分段控件的主要属性
    //当前选项 sender.selectedSegmentIndex
    if (sender.selectedSegmentIndex == 0) {
        self.leftSwitch.hidden = NO;
        self.rightSwitch.hidden = NO;
        self.btnall.hidden = YES;
    }
    else
    {
        self.leftSwitch.hidden = YES;
        self.rightSwitch.hidden = YES;
        self.btnall.hidden = NO;
    }
    
}

- (IBAction)sliderchage:(UISlider *)sender {
    //将滑块的数值赋给value
    int value = sender.value;
    //将label的数值用value显示
    self.infolabel.text = [NSString stringWithFormat:@"%i",value];
    

}

- (IBAction)swicthchange:(UISwitch *)sender {
    //控制开关当前状态
    BOOL open = sender.on;
    //设置状态是否带上动画
    [self.leftSwitch setOn:open animated:YES];
    [self.rightSwitch setOn:open animated:NO];
}

- (IBAction)btnchange:(id)sender {
    UIActionSheet *showsheet = [[UIActionSheet alloc]initWithTitle:@"信息错误" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"查看错误" otherButtonTitles:nil, nil];
    [showsheet showInView:self.view];
    
    }
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.destructiveButtonIndex) {
        NSString *nameinfo = [NSString stringWithFormat:@"%@  用户信息不存在",self.nameText.text];
        UIAlertView *view = [[UIAlertView alloc]initWithTitle:@"错误信息" message:nameinfo delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [view show];
    }
}



@end
